﻿using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class ProcedureLaunch : ProcedureBase
    {
        public override void OnEnter()
        {
            Process().Forget();
        }

        private async UniTaskVoid Process()
        {
            //GameRenderLOD.SetResolution(720);
            //GameRenderLOD.LockFrame(FrameworkEntry.Instance.FrameRate);
            //ManagerCenter.Render.SetLODLevel(Rendering.GameRender.LODLevel.Medium);

            //SplashScreen.Instance.Show();
            SettingModule.Instance.Initialize();

            //Init SDK
            bool initSdkResult = await SDKModule.Instance.InitSDK();
            if (!initSdkResult)
            {
                NoticeModule.ShowNotice(NoticeConstant.ID_ON_SDK_INIT_FAIL, () =>
                {
                    Application.Quit();
                });
                return;
            }
            //Init NetModule
            CGameNetHandler.Instance.Init();

            NetManager.Instance.CreateNetworkChannel(NetworkChannelName.Game, 15, 1, 1000000);
            NetManager.Instance.CreateNetworkChannel(NetworkChannelName.Logic, 15, 1000001, 2000000);

            ChangeState<ProcedureLogin>();
        }

        public override void OnLeave()
        {

        }

        public override void OnUpdate(float deltaTime, float unscaledDeltaTime)
        {

        }
    }
}
